package org.foj.model {

import mx.messaging.ChannelSet;
import mx.rpc.AsyncToken;
import mx.rpc.IResponder;
import mx.rpc.remoting.RemoteObject;
import mx.rpc.soap.WebService;

import org.foj.dto.Comment;

public class CommentModel {

    private var _commentService:WebService;

    public function CommentModel() {

        _commentService = new WebService();
        _commentService.wsdl =
                "http://localhost:8080/services/CommentService?wsdl";
        if (_commentService.canLoadWSDL()) {
            _commentService.loadWSDL();
        }
    }

    public function getCommentsForIssueId(issueId:Number,
                                          responder:IResponder):void {
        var token:AsyncToken = _commentService.findCommentsByIssueId(issueId);
        token.addResponder(responder);
    }

    public function saveComment(comment:Comment,
                                responder:IResponder):void {
        var token:AsyncToken = _commentService.save(comment);
        token.addResponder(responder);
    }

    public function removeComment(id:Number,
                                  responder:IResponder):void {
        var token:AsyncToken = _commentService.remove(id);
        token.addResponder(responder);
    }
}
}